約 4,560,310 件
https://w.atwiki.jp/eyes_33/pages/31.html
Scaffolding(スキャフィールディング)を使ってみよう! まずは、作っちゃったモデルとかを削除 モデルの削除は、destoryで rails destroy model book DBの削除も[rake]で rake db drop で、scaffoldでモデル等を生成 rails g scaffold book isbn string title string price integer publish string published date cd boolean 単にモデル作る時のコマンドが、modelからscaffoldになっただけ モデルとかができたら、後はテーブル作成すればOK! rake db migrate 後は、URL叩けばActiveRecordにいきなりアクセス可能!こりゃ簡単だ!すごいね! http //localhost 3000/books Scaffoldingで作られたルートって、結構すごいよ。 実は、config/routes.rbには以下の記述があるだけ。 resources books でも、これ結構いろいろやってくれるらしい。[rake routes]で確認すると…? C \user\dev\railbook rake routes books GET /books(. format) { action= "index", controller= "books"} POST /books(. format) { action= "create", controller= "books"} new_book GET /books/new(. format) { action= "new", controller= "books"} edit_book GET /books/ id/edit(. format) { action= "edit", controller= "books"} book GET /books/ id(. format) { action= "show", controller= "books"} PUT /books/ id(. format) { action= "update", controller= "books"} DELETE /books/ id(. format) { action= "destroy", controller= "books"} / controller(/ action(/ id(. format))) とまあ、基本的なbooksへのアクセスルートを設定してくれるんだ!すごいね、これ。 Scaffoldingの各アクション アクションは例によって、[app/controllers/books_controller.rb]ですね。 index(一覧) 短い割には、意外に色々詰まってるindexのアクションメソッド def index @books = Book.all respond_to do |format| format.html # index.html.erb format.json { render json @books } end end 上記のrespond_toでフォーマット毎の出力をするらしい。 普通はHTMLなんでindex.html.erbで表示して、[http //localhost 3000/books.json]みたいだとJSON形式で表示 でテンプレートでは、ついにヘルパーがお出まし link_toではリンクを生成(そりゃそうかw) テンプレート側がこうだと、 %= link_to New Book , new_book_path % 出力HTMLはこんな感じ a href="/books/new" New Book /a new_book_pathは、ルート定義されたビューヘルパーなんだ!他にもいろいろ自動生成されてるよ。 これ、すげーな。 td %= link_to Show , book % /td って書くと、渡されたbookオブジェクトを元に、[book.id]を取得しようとして、自動でIDを降ってこんな感じでHTML出力される! td a href="/books/1" Show /a /td 確認画面も簡単に出せるんだ! td %= link_to Destroy , book, confirm Are you sure? , method delete % /td へー。出力結果を見ると、data-confirmが定義されてるだけなのか。 td a href="/books/1" data-confirm="Are you sure?" data-method="delete" rel="nofollow" Destroy /a /td これが、Rails3の 控えめなJavaScript(Unobtrusive JavaScript) ってことなんだねー。 show(詳細表示) アクションだと、params[ id]で、URLの[/books/1]の1を取れる。この形式でリクエストも取れるらしい。 @book = Book.find(params[ id]) new/create(登録) newは新規登録画面を出すアクションで、createは実際の登録のアクションだね。 あれ?newのテンプレートに、formの記述がこれしかない… %= render form % おおー、実体は[_form.html.erb]の方なんだ。 なるほどね。登録と更新でほとんど一緒のformだから、部分テンプレートにしてるのか。かしこいなー。 うお!createでのパラメタ取得、めちゃくちゃ簡単なんだ! @book = Book.new(params[ book]) これだけで、bookオブジェクトでき上がりとは…。 この場合、params[ book]で、フォームのbook[***]の値を全部取ってくるらしい。 後は、@book.save で登録するだけか…。なんと簡単な…。 Scaffoldingのcreateメソッドでは、ちゃんと登録済み確認して、redirect_toでnoticeを出すらしい。 def create @book = Book.new(params[ book]) respond_to do |format| if @book.save format.html { redirect_to @book, notice Book was successfully created. } format.json { render json @book, status created, location @book } else format.html { render action "new" } format.json { render json @book.errors, status unprocessable_entity } end end end あ、ここで指定したnoticeが、show.html.erbの一番上のnoticeに出るわけねー。良くできてるわ。 p id="notice" %= notice % /p しかも、エラー時は@bookをそのまま使ってnew画面を出すから、入力データはそのまま表示されるのか!あったまいい! edit/update(更新) editアクションはパラメタからID取って表示するだけ。 updateアクションも、基本の構造はcreateと一緒。違うのは@book.saveじゃなくて、@book.update_attributesを使うってとこ。 def update @book = Book.find(params[ id]) respond_to do |format| if @book.update_attributes(params[ book]) format.html { redirect_to @book, notice Book was successfully updated. } format.json { head ok } else format.html { render action "edit" } format.json { render json @book.errors, status unprocessable_entity } end end end @book.update_attributesは内部的にsaveを呼んでるから、savaのコールは不要 JSONでの更新成功時にある[head ok]は、HTTPのステータスのみでコンテンツなしを返す便利メソッド。ここでは[200 OK]を返すって訳 format.json { head ok } edit.html.erbは、newとeditで共通の部分テンプレートだけど、結構面白い。 %= form_for(@book) do |f| % このform_forって、オブジェクトが空だとその後の出力がいろいろと変化するらしい。 ------------- 空(new) 値あり(edit) 送信先アドレス /books /books/1 HTTPメソッド post put(疑似) 実際にはputはブラウザが対応してないから、hiddenで[name="_method" value="put"]って書いて、Railsで疑似ってるんだー まあ、なんか面倒だけど例の「RESTfulインタフェース」の方針に従っての実装なんだねー。つうか、ブラウザ頑張れよってことかw destroy(削除) 削除は、単に@book.destroyするだけ。 def destroy @book = Book.find(params[ id]) @book.destroy respond_to do |format| format.html { redirect_to books_url } format.json { head ok } end end ここでも、JSON時は[head ok]のみ返す感じ。 -
https://w.atwiki.jp/volo/pages/40.html
2.1 RSPECを使う http //playet.jugem.jp/?eid=73 database.yml http //brass.to/blog/database_yml.html 一般 Rails 2.0 をインストールしてみた http //d.hatena.ne.jp/elm200/20080222/1203666414 Rails 2.0のscaffoldを使ってみた http //d.hatena.ne.jp/idesaku/20071211/1197386955 Rails2.0でデバッグする新しいやり方 http //blog.s21g.com/articles/304 Rails 2.0.2 でMySQLを使う http //fdays.blogspot.com/2007/12/rails-202-mysql.html Rails 2.0 移行ログ http //www.fraction.jp/log/archives/2008/01/24/Migrate_from_Rails_12x_to_20 AAA関連 解消法 open_id_authenticationプラグイン(rails 2.0.2) http //koress.jp/2008/01/_open_id_authenticationrails_2.html Rails2.0を使うとき注意すること(login plugin関連) http //d.hatena.ne.jp/tetsuarossa/20080114/p1
https://w.atwiki.jp/sawa2/pages/14.html
Rails Railsの習慣とかフレームワークは秀逸。 それに従うだけで自然に整理整頓されたコード群ができあがるというところがとても魅力的。 大きなアプリケーションを作るのに向いているということなのかな。 大きくなれるからTwitterのように落ちたりすると「やっぱりRailsは早熟」といわれちゃったりする。 RDocはhttp //railsapi.com/doc/rails-v2.3.8/ここのがおすすめです。 app アプリケーションとしての機能を記述する。Railsの表舞台。 controllers helpers models views config 設定ファイル群ですね。gemをロードしたり、I18n(国際化)のための定義ファイルがあったり。 db データベースに関する記述をする。テーブルは把握しやすい構造にしておきたい。ここでは、結構地味な作業が必要なんですね。 public images javascripts stylesheets script サーバー、コンソール、ジェネレーター、、、Railsアプリケーションに魂を宿すスクリプトがこの中に。 vendor 主に他の人たち(vendorってことなんじゃないかな)が作ったコード/プラグインを置いておきます。 バージョン Rails 2.3.5, Rails 2.3.6, Rails 2.3.7, Rails 2.3.8
https://w.atwiki.jp/sami1127/pages/10.html
のぉ。。Ruby書き方でハマっとるがな。全然先進んで無いがな。。頑張ります。。 scaffoldなるものを使ってDB登録・参照機能を作ってみようかと。 まずはModel・View・Contlollerの作成から。 プロンプトで以下実行 ruby script/generate scaffold book title string author string publisher string isbn string published_on date で、このModelにあわせてTableを作成 rake db migrate で、サーバースタートして、アクセス! http //localhost 3000/books うん、出来た☆彡 … … … …気持ち悪ぃー。。。。。 何これ。何でこれで全部できるの。 つかなんで全自動なのっ こりゃ確かに簡単に作れるわ。 色々カスタマイズできるようだし。。 にしても。。なんかなぁ。。。 ちなみにこれ作るときに教えてもらったんですが、 ruby script/destroy model book これで作ったModelらへん(?)削除出来て、 ruby script/destroy scaffold book これでscaffoldらへんで作ったのが(?)削除出来る、 らしい!←よくわかってない。 rake db migrate -version=0 で、これがVersion設定しとるのか? なんかマイグレーションする前にやってたんだけど、まだ調べてない。。。後で調べます。。
https://w.atwiki.jp/rubyocho/pages/14.html
Rails動作確認 テスト・スクリプトの起動 データベース接続 SQLiteの確認 itemモデルを生成 vi config/database.yml SQLite3のデータベースを作る。テーブルを作る itemモデル サービス起動 ブラウザから閲覧 http //localhost 3000/items/ サービス停止 テスト・スクリプトの起動 ユーザのホーム・ディレクトリから rails testapp cd testapp サービス起動 $ ruby script/server = Booting WEBrick... = Rails application started on http //0.0.0.0 3000 = Ctrl-C to shutdown server; call with --help for options [2007-05-06 14 00 12] INFO WEBrick 1.3.1 [2007-05-06 14 00 12] INFO ruby 1.8.5 (2006-08-25) [i386-linux] [2007-05-06 14 00 12] INFO WEBrick HTTPServer#start pid=2344 port=3000 ブラウザから閲覧 http //localhost 3000/ サービス停止 CTL+C [2007-05-06 14 14 13] INFO going to shutdown ... [2007-05-06 14 14 13] INFO WEBrick HTTPServer#start done. データベース接続 SQLiteの確認 itemモデルを生成 ruby script/generate model item exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/item.rb create test/unit/item_test.rb create test/fixtures/items.yml create db/migrate create db/migrate/001_create_items.rb vi config/database.yml development adapter sqlite3 database dev.db SQLite3のデータベースを作る。テーブルを作る $ sqlite3 dev.db SQLite version 3.3.6 Enter ".help" for instructions sqlite CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT); sqlite .quit itemモデル $ ruby script/generate scaffold item exists app/controllers/ exists app/helpers/ create app/views/items exists app/views/layouts/ exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ identical app/models/item.rb identical test/unit/item_test.rb identical test/fixtures/items.yml create app/views/items/_form.rhtml create app/views/items/list.rhtml create app/views/items/show.rhtml create app/views/items/new.rhtml create app/views/items/edit.rhtml create app/controllers/items_controller.rb create test/functional/items_controller_test.rb create app/helpers/items_helper.rb create app/views/layouts/items.rhtml create public/stylesheets/scaffold.css サービス起動 $ ruby script/server = Booting WEBrick... = Rails application started on http //0.0.0.0 3000 = Ctrl-C to shutdown server; call with --help for options [2007-05-06 15 15 03] INFO WEBrick 1.3.1 [2007-05-06 15 15 03] INFO ruby 1.8.5 (2006-08-25) [i386-linux] [2007-05-06 15 15 03] INFO WEBrick HTTPServer#start pid=3416 port=3000 ブラウザから閲覧 http //localhost 3000/items/ データ一覧から新規作成 データ入力 入力ができて、データ一覧 サービス停止 CTL+C [2007-05-06 14 14 13] INFO going to shutdown ... [2007-05-06 14 14 13] INFO WEBrick HTTPServer#start done.
https://w.atwiki.jp/sawa2/pages/46.html
Rails Rails 2.3.6 http //weblog.rubyonrails.org/2010/5/23/ruby-on-rails-2-3-6-released のてきとーな翻訳です。 Ruby on Rails 2.3.6リリース Jeremy Kemperにより2010/05/23に投稿されたものです。 私たちはRuby on Rails 2.3.6をリリースしましたよ。その内容は、6ヶ月に及ぶバグフィックス、いくつかの新しい特徴、Rails 3への大きな架け橋となります。 Rails 2.3.6に含まれる古くて使われない特徴をdeprecated(将来消される機能)にしました。なので、Rails 3では、それらが完全に消される可能性があります。もし、Rails 2.3.6上でのアプリケーションがdeprecation warning無しで動くのであれば、上手く移行できるでしょう。 このじっくりと作られた料理が有志による87人によりもたらされてます。 では、ごちそうをいただきましょう。 Action Pack Rackを1.0.1から1.1.0へアップデート XSS(クロスサイトスクリプティング)対策 Rails 3に合わせ(?) http //github.com/rails/rails_xss のものを公式プラグインとした クッキー convenient cookie jar add-ons to set permanent or signed cookies, or both at once cookies.permanent.signed[ remember_me] = current_user.id. さらに読む Flash もっとも一般的なキーであるalertとかnoticeとかをもっと使えるようにした。 self.alert = ... self.notice = ... とかが使える。 redirect_to url, alert = ... redirect_to url, notice = ... も加えた。さらに読む i18n(国際化) labelヘルパをローカルに(?) Active Record 名前空間(Namespacing) support optional table name prefixes on modules by defining self.table_name_prefix. さらに読む Destroy uses optimistic locking. Counter cache use Post.reset_counters(1234, comments) to count the number of comments for post 1234 and reset its comments_count cache. PostgreSQL サポートしていれば、常にstandard-conforming stringsを使う。 MySQL add indexにlengthのオプションをつけることができるようになった。。さらに読む MySQL add_columnとchange_columnに first = trueと after = other_columnの引数をつけることで、コラムの位置を変更できる。 Active Support i18nを1.3.3から1.3.7にアップグレード。 TZInfoを0.3.12から0.3.16へアップグレード。 マルチバイト speed up string verification and cleaning. JSON 可能であれば、JSONデコードのためにYAJLを使おう。 gem install yajl-ruby Testing add assert_blank and assert_present. Read more Core backport Object#singleton_class from Ruby 1.8.8, deprecating our Object#metaclass. Core add Object#presence that returns the object if it’s #present? otherwise returns nil. Example region = params[ state].presence || params[ country].presence || US Core add Enumerable#exclude? to match include?. Core rename Array#rand to Array#random_element to avoid collision with Kernel#rand. Core rename Date# and Time#last_(month|year) to #prev_(month|year) for Ruby 1.9 forward compatibility. Active Resource JSON ActiveResource Base.include_root_in_json = true とすると、to serialize as a hash of model name - attributes instead of a bare attributes hash。デフォルトはfalseです。 Action Mailer TMailを1.2.3から1.2.7にアップグレード。 Railties RubyGems 1.3.6 deprecation warningを出さない。 詳しくは、コミットログを読んでください。
https://w.atwiki.jp/kiminori_hirose/pages/16.html
Rails 1.2.3 のメモ 作成手順 プロジェクトの作成 projectプロジェクトを作成する。 $ rails project データベースの設定 config/database.ymlをMySQL用に編集する。(testとproductionもdevelopmentと同様に変更しておく。) development adapter mysql database project_development username {MySQLのユーザ名} password {パスワード} socket /var/lib/mysql/mysql.sock #ソケットのとき host localhost #TCP/IPのときのMySQLのホスト名 port 3306 #TCP/IPのときのMySQLのポート番号。指定してないときは、3306になる encoding utf8 #文字化け防止のためデータベースの文字コードを設定する。 文字コード(UTF-8)の指定 app/controllers/application.brにHTTPレスポンスで返すContent-Typeを追加する。 class ApplicationController ActionController Base after_filter set_charset protected def set_charset headers["Content-Type"] = text/html; charset=UTF-8 end end config/environment.rbにRailsの内部文字コードを追加する。 $KCODE = UTF8 Tips Railsの規約にあわない名前を持つテーブルのためにset_table_name を使う config/environment.rbファイルを編集 ActiveRecord Base.pluralize_table_names = false app/controllers/entity.rbを編集 class Entity ActiveRecord Base set_table_name "entity" end 主キーがidではないテーブルのためにset_primary_keyを使う app/controllers/entity.rbを編集 class Entity ActiveRecord Base set_primary_key "entity_id" end ActiveRecordで外部キーを指定する class Person ActiveRecord Base belongs_to company validates_associated campany end 独自の単数形と複数形を定義する config/environment.rbを編集 Inflector.inflections do |inflect| inflect.irregular leaf , leaves end セッションの有効期限を設定する プロジェクト全体で設定するには、config/environment.rbを編集 ActionController Base.session_options[ session_expires] = 15.minutes.from_now 特定のコントローラで設定するには、各コントローラを編集 class PersonController Application session session_expires = 10.minutes.from_now end HTMLエスケープとURIエンコード HTMLエスケープ a href=" %=h http //localhost/q=東京 -% " LINK /a URIエンコード a href=" %=u http //localhost/q=東京 -% " LINK /a
https://w.atwiki.jp/soscomp/pages/34.html
「経験値上昇みててね☆」 - by はるかねえさま 最近流行のRuby on Railsについてのメモ。 こちらはRails 2.x対応のメモになります。 Rails 1.xに関することはRuby on Rails (old)でも見やがってください。 Railsとは Railsを使う上で インストールActiveScriptRuby + gem + sqlite3でWindwos上にインストールする場合 Hello World Railsとは 最近注目されているWebアプリケーションフレームワーク。 Webアプリケーションフレームワークとは、さまざまな雛形やプロジェクト管理の仕組みを提供することで、Webアプリケーションの開発を用意にするための開発環境のことです。 Railsはそれそのものが主にRubyで書かれていて、開発もRubyで行います。 簡単、便利、強力なRubyをWebアプリケーション開発において更に便利に使うことが可能になるわけです。 Railsがどんなものか、より具体的な解説は以下のサイトでわかりやすく解説されています。 Ruby on Rails入門 第1回:Railsが注目されている理由 - ThinkIT Railsを使う上で Ruby on RailsはRubyのオブジェクト指向を理解したうえで、HTML、SQLの知識を 複合して使うものですHTMLの部分はフレームワークとして組み込まれているので、 実際に使うことは少ないですが、ブラックボックスを少なくするということは、 プログラムを組む上で大事なことなので、理解は大事です。 インストール Railsは単一の実行ファイルからなるアプリケーションではなく、複数のソフトウェアが組み合わさって動いています。 なので、環境構築はそれなりに大変です。 ActiveScriptRuby + gem + sqlite3でWindwos上にインストールする場合 ActiveScriptRubyのインストール C \ruby\ にインストール C \ruby\bin\ にパスを通す SQLite3のインストール SQLite Download Pageからsqlitedll-3_x_xx.zipをダウンロード。 解凍して中身を C \ruby\bin\ に入れる。 # パスの通っているディレクトリならどこでもいい sqlite3-rubyのインストール 最新版はまだWindowsに対応してないらしいのでちょっと枯れたやつを入れる。 コマンドプロンプトかWindows Power Shellを開いて、 gem install sqlite3-ruby --version = 1.2.3 Railsのインストール コマンドプロンプトかWindows Power Shellを開いて、 gem install rails -y Hello World Scaffoldで簡単なデータベースWebアプリを作ってみる 参考 http //d.hatena.ne.jp/idesaku/20071211/1197386955 http //d.hatena.ne.jp/GARAPON/20081022/1224657975 http //www.be-styles.jp/archives/558 http //blogs.wankuma.com/pinzolo/archive/2008/12/04/162786.aspx 名前 コメント このページへのアクセス数 total - today - yesterday - このページのタグ一覧 RoR みみなし 背後
https://w.atwiki.jp/sasasa123/pages/1074.html
Scaffold Stacking テト譜 このテンプレのポイント 土台 片側セットアップ率 左右反転込みセットアップ率 このテンプレの弱み 派生一覧 テンプレ概要 類似関係 外部サイト その他
https://w.atwiki.jp/rubyonrails/pages/17.html
用語解説 RubyGems Rubyのパッケージ管理システム。 gem search 実行結果 *** LOCAL GEMS *** actionmailer (2.3.4) actionpack (2.3.4) activerecord (2.3.4) activeresource (2.3.4) activesupport (2.3.4) fxri (0.3.6) fxruby (1.6.16) hpricot (0.6.164) log4r (1.0.5) ptools (1.1.6) rack (1.0.1) rails (2.3.4) rake (0.8.7, 0.8.1) ruby-opengl (0.60.0) sqlite3-ruby (1.2.5) test-unit (2.0.1) win32-api (1.2.1, 1.2.0) win32-clipboard (0.4.4) win32-dir (0.3.2) win32-eventlog (0.5.0) win32-file (0.5.5) win32-file-stat (1.3.1) win32-process (0.5.9) win32-sapi (0.1.4) win32-sound (0.4.1) windows-api (0.2.4) windows-pr (0.9.3) gem ヘルプ gem -h 実行結果 RubyGems is a sophisticated package manager for Ruby. This is a basic help message containing pointers to more information. Usage gem -h/--help gem -v/--version gem command [arguments...] [options...] Examples gem install rake gem list --local gem build package.gemspec gem help install Further help gem help commands list all gem commands gem help examples show some examples of usage gem help platforms show information about platforms gem help COMMAND show help on COMMAND (e.g. gem help install ) Further information http //rubygems.rubyforge.org gem コマンド一覧 gem help commands 実行結果 GEM commands are build Build a gem from a gemspec cert Manage RubyGems certificates and signing settings check Check installed gems cleanup Clean up old versions of installed gems in the local repository contents Display the contents of the installed gems dependency Show the dependencies of an installed gem environment Display information about the RubyGems environment fetch Download a gem and place it in the current directory generate_index Generates the index files for a gem server directory help Provide help on the gem command install Install a gem into the local repository list Display gems whose name starts with STRING lock Generate a lockdown list of gems mirror Mirror a gem repository outdated Display all gems that need updates pristine Restores installed gems to pristine condition from files located in the gem cache query Query gem information in local or remote repositories rdoc Generates RDoc for pre-installed gems search Display all gems whose name contains STRING server Documentation and gem repository HTTP server sources Manage the sources and cache file RubyGems uses to search for gems specification Display gem specification (in yaml) stale List gems along with access times uninstall Uninstall gems from the local repository unpack Unpack an installed gem to the current directory update Update the named gems (or all installed gems) in the local repository which Find the location of a library file you can require For help on a particular command, use gem help COMMAND . Commands may be abbreviated, so long as they are unambiguous. e.g. gem i rake is short for gem install rake . scaffold 「scaffold」(スキャフォゥド 「足場」という意味) scaffoldを使うと、一連の操作を行うための画面やその裏側の処理を行うプログラムを自動生成できます。 一覧表示(ページング機能付き) 単票形式のデータ表示 新規登録 編集 削除 scaffoldの利用方法 ruby script/generate scaffold -h 実行結果 Usage script/generate scaffold ModelName [field type, field type] Options --skip-timestamps Don t add timestamps to the migration file for this model --skip-migration Don t generate a migration file for this model --force-plural Forces the generation of a plural ModelName Rails Info -v, --version Show the Rails version number and quit. -h, --help Show this help message and quit. General Options -p, --pretend Run but do not make any changes. -f, --force Overwrite files that already exist. -s, --skip Skip files that already exist. -q, --quiet Suppress normal output. -t, --backtrace Debugging show backtrace on errors. -c, --svn Modify files with subversion. (Note svn must be in path) -g, --git Modify files with git. (Note git must be in path) Description Scaffolds an entire resource, from model and migration to controller and views, along with a full test suite. The resource is ready to use as a starting point for your RESTful, resource-oriented application. Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs. Attribute pairs are column_name sql_type arguments specifying the model s attributes. Timestamps are added by default, so you don t have to specify them by hand as created_at datetime updated_at datetime . You don t have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately. For example, scaffold post title string body text published boolean gives you a model with those three attributes, a controller that handles the create/show/update/destroy, forms to create and edit your posts, and an index that lists them all, as well as a map.resources posts declaration in config/routes.rb. If you want to remove all the generated files, run script/destroy scaffold ModelName . Examples `./script/generate scaffold post` `./script/generate scaffold post title string body text published boolean` `./script/generate scaffold purchase order_id integer amount decimal` rake Rubyのビルドツール(AntやMake等) rake オプション一覧 rake -h 実行結果 rake [-f rakefile] {options} targets... Options are ... -C, --classic-namespace Put Task and FileTask in the top level namespace -D, --describe [PATTERN] Describe the tasks (matching optional PATTERN), then exit. -n, --dry-run Do a dry run without executing actions. -e, --execute CODE Execute some Ruby code and exit. -p, --execute-print CODE Execute some Ruby code, print the result, then exit. -E, --execute-continue CODE Execute some Ruby code, then continue withnormal task processing. -I, --libdir LIBDIR Include LIBDIR in the search path for required modules. -P, --prereqs Display the tasks and dependencies, then exit. -q, --quiet Do not log messages to standard output. -f, --rakefile [FILE] Use FILE as the rakefile. -R, --rakelibdir RAKELIBDIR Auto-import any .rake files in RAKELIBDIR.(default is rakelib ) --rakelib -r, --require MODULE Require MODULE before executing rakefile. --rules Trace the rules resolution. -N, --no-search, --nosearch Do not search parent directories for the Rakefile. -s, --silent Like --quiet, but also suppresses the in directory announcement. -g, --system Using system wide (global) rakefiles (usually ~/.rake/*.rake ). -G, --no-system, --nosystem Use standard project Rakefile search paths, ignore system wide rakefiles. -T, --tasks [PATTERN] Display the tasks (matching optional PATTERN) with descriptions, then exit. -t, --trace Turn on invoke/execute tracing, enable full backtrace. -v, --verbose Log message to standard output. -V, --version Display the program version. -h, -H, --help Display this help message. rake タスク一覧 rake -T タスク一覧が見られます(注意:-T 小文字じゃだめ) 参考:Ruby on Railsでrakeコマンドを使って様々なタスクを実行しよう マイグレーション DBのバージョン管理システム。 具体的には次のような仕組みです。 db/migrateディレクトリ配下にdb/migrate/20080728204433_create_categories.rbのように、DBに対する変更内容が記述されたファイルを配置 このとき、各ファイル名の先頭には「20080728204433」の部分のように、タイムスタンプに基づくバージョン情報が付く マイグレーションは現在のDBのバージョン情報を保持する。これにより、db/migration内のファイルのうち、どれがDBに反映されて、どれが反映されていないかが分かる 「db migrate」というrakeタスク(「make install」のようなバッチ処理をイメージすると分かりやすい)を実行して、未反映の変更をDBに反映させることができる(=最新状態までバージョンアップ) バージョン情報を指定してrakeタスクを実行し、バージョンを任意のバージョンにバージョンアップ、バージョンダウンさせることもできる